//
//  CZQAddressViewController.m
//  LoveBeer
//
//  Created by 崔正强 on 17/5/4.
//  Copyright © 2017年 崔正强. All rights reserved.
//

#import "CZQAddressViewController.h"
#import "CZQAddressLocationCell.h"
#import "LoveBeer.pch"
#import <Masonry.h>
#import "CZQLoginViewController.h"

@interface CZQAddressViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak,nonatomic) UIView *logView;

@end

@implementation CZQAddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma - 添加tableView -
- (void)addtableView {
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGScreenFrame style:UITableViewStyleGrouped];
    [self.view addSubview:tableView];
    tableView.dataSource = self;
    tableView.delegate = self;
    
    tableView.rowHeight = 60;
    
    [tableView registerClass:[CZQAddressLocationCell class] forCellReuseIdentifier:@"location"];
    
}

- (void)addLogView {
    UIView *logView = [[UIView alloc] init];
    _logView = logView;
    logView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:logView];
    [logView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.width.height.mas_equalTo(ScreenWidth);
    }];
    
    //设置登录按钮
    UIButton *logBtn = [[UIButton alloc] init];
    [logView addSubview:logBtn];
    [logBtn setTitle:@"登录" forState:UIControlStateNormal];
    [logBtn setBackgroundColor:appColor];
    [logBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    logBtn.layer.masksToBounds = YES;
    logBtn.layer.cornerRadius = 10;
    
    //添加点击跳转事件
    [logBtn addTarget:self action:@selector(logBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [logBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(logView);
        make.width.mas_equalTo(260);
        make.height.mas_equalTo(40);
    }];
    
    UILabel *lable = [[UILabel alloc] init];
    [logView addSubview:lable];
    lable.textAlignment = NSTextAlignmentCenter;
    [lable sizeToFit];
    lable.text = @"查看已有配送地址请先登录";
    lable.font = [UIFont systemFontOfSize:13];
    lable.textColor = [UIColor lightGrayColor];
    
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(logView);
        make.top.equalTo(logBtn.mas_bottom).offset(7);
    }];
}

- (void)logBtnClick {
    
    CZQLoginViewController *vc = [[CZQLoginViewController alloc] init];

    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma - 数据源方法 -

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        CZQAddressLocationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"loation" forIndexPath:indexPath];
        return cell;
    }
    return [UITableViewCell new];
}

#pragma - 代理方法 -

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}



@end
